#define _CRT_SECURE_NO_WARNINGS 1

  struct TreeNode {
 	int val;
 	struct TreeNode *left;
 	struct TreeNode *right;
 	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  };
 
class Solution {
public:
    void _mergeTrees(TreeNode* cur1, TreeNode* cur2)
    {
        if (cur2 == nullptr)
        {
            return;
        }
        cur1->val += (cur2->val);
        if (cur1->left == nullptr && cur2->left != nullptr)
        {
            cur1->left = cur2->left;
        }
        else
        {
            _mergeTrees(cur1->left, cur2->left);
        }
        if (cur1->right == nullptr && cur2->right != nullptr)
        {
            cur1->right = cur2->right;
            return;
        }
        else
        {
            _mergeTrees(cur1->right, cur2->right);
        }
    }
    TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2)
    {
        if (t1 == nullptr) return t2;
        _mergeTrees(t1, t2);
        return t1;
    }
};